<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const { directLine, store } = testHelpers.createDirectLineEmulator();

        WebChat.renderWebChat(
          {
            directLine,
            store
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          text: "Hi! I'm Cody, the devbot. How can I help?"
        });

        await directLine.emulateIncomingActivity({
          from: { role: 'user' },
          text: "Can you explain how to configure PAD's proxy settings?"
        });

        await directLine.emulateIncomingActivity({
          additionalType: ['AIGeneratedContent'],
          entities: [
            {
              '@context': 'https://schema.org',
              '@id': '',
              '@type': 'Message',
              citation: [
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    url: 'https://learn.microsoft.com/en-us/entra/identity/app-proxy/conceptual-deployment-plan',
                    usageInfo: {
                      '@type': 'CreativeWork',
                      additionalType: 'https://copilotstudio.microsoft.com/sensitivity-labels/v1',
                      name: 'General'
                    }
                  },
                  claimInterpreter: {
                    '@type': 'Project',
                    slogan: 'Surfaced with Azure OpenAI',
                    url: 'https://learn.microsoft.com/en-us/azure/ai-services/openai/overview'
                  },
                  position: 1
                },
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    url: 'https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1'
                  },
                  claimInterpreter: {
                    '@type': 'Project',
                    slogan: 'Surfaced with Azure OpenAI',
                    url: 'https://learn.microsoft.com/en-us/azure/ai-services/openai/overview'
                  },
                  position: 2
                },
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    name: 'How to renew authentication token',
                    url: 'https://learn.microsoft.com/en-us/entra/identity-platform/refresh-tokens',
                    usageInfo: {
                      '@id': '_:s1',
                      '@type': 'CreativeWork',
                      additionalType: 'https://copilotstudio.microsoft.com/sensitivity-labels/v1',
                      description:
                        'Data is classified as Confidential but is NOT PROTECTED to allow access by approved NDA business partners. If a higher level of protection is needed please change the sensitivity level of the cited content.',
                      keywords: ['encrypted-content'],
                      name: 'Confidential\\Any User (No Protection)',
                      pattern: {
                        '@type': 'DefinedTerm',
                        inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
                        name: 'color',
                        termCode: 'orange'
                      }
                    }
                  },
                  claimInterpreter: {
                    '@type': 'Project',
                    slogan: 'Surfaced with Azure OpenAI',
                    url: 'https://learn.microsoft.com/en-us/azure/ai-services/openai/overview'
                  },
                  position: 3
                }
              ],
              type: 'https://schema.org/Message',
              usageInfo: { '@id': '_:s1' }
            }
          ],
          text: 'Sure, you should override the default proxy settings[1]​[2], when your proxy server requires authentication[3].\n\n[1]: https://learn.microsoft.com/en-us/entra/identity/app-proxy/conceptual-deployment-plan#application-discovery "IT - Proxy Settings for external access"\n[2]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1#ID0EFD=Windows_11 "Changing proxy settings - Windows 11"\n[3]: https://learn.microsoft.com/en-us/entra/identity-platform/refresh-tokens "How to renew authentication token"\n',
          type: 'message'
        });

        await host.snapshot();

        const activityElement = pageElements.activities()[2];

        const linkDefinitions = activityElement.querySelectorAll('.webchat__link-definitions__list-item');

        expect(linkDefinitions).toHaveProperty('length', 3);

        expect(linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('A');
        expect(
          linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('IT - Proxy Settings for external access');
        expect(linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-badge')).toHaveProperty(
          'textContent',
          'General'
        );
        expect(
          linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-badge').getAttribute('title')
        ).toBe('General');

        expect(linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('A');
        expect(
          linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('Changing proxy settings - Windows 11');
        expect(linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-badge')).toBeNull();

        expect(linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('A');
        expect(
          linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('How to renew authentication token');
        expect(
          linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-badge').getAttribute('title')
        ).toBe(
          'Confidential\\Any User (No Protection)\n\nData is classified as Confidential but is NOT PROTECTED to allow access by approved NDA business partners. If a higher level of protection is needed please change the sensitivity level of the cited content.'
        );

        expect(document.querySelector('.webchat__link-definitions__header-text')).toHaveProperty(
          'textContent',
          '3 references'
        );

        expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label-text')).toHaveProperty(
          'textContent',
          'Confidential\\Any User (No Protection)'
        );

        expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label')).toHaveProperty(
          'title',
          'Confidential\\Any User (No Protection)\n\nData is classified as Confidential but is NOT PROTECTED to allow access by approved NDA business partners. If a higher level of protection is needed please change the sensitivity level of the cited content.'
        );

        expect(
          document.querySelector('.webchat__link-definitions__message-sensitivity-label--is-encrypted')
        ).toBeTruthy();
      });
    </script>
  </body>
</html>
